package com.charactereducation.admin.controller.index;

import com.charactereducation.module.AdminMenu;
import com.charactereducation.module.AdminUser;
import com.charactereducation.admin.service.MenuService;
import com.charactereducation.tools.def.Constant;
import com.charactereducation.webcore.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Baggio on 2017/2/22.
 */
@RequestMapping("/admin")
@Controller
public class IndexContorller extends BaseController {
    @Autowired
    MenuService menuService;

    @RequestMapping(value = "/index")
    public ModelAndView getAdvert(HttpServletRequest request) {
        System.out.println("=============================index==============================================>>>>>>");
        ModelAndView mov = new ModelAndView();
        mov.setViewName("admin/index");
        Map<String, String> map = new HashMap<>();
        AdminUser adminUser =(AdminUser)super.session.getAttribute(Constant.SESSION_KEY_ADMIN_USER_LOGIN);
        logger.info("adminUser===>>" + adminUser.toString());
        map.put("roleId", String.valueOf(adminUser.getRoleId()));
        map.put("tid", String.valueOf(adminUser.getTid()));
        List<AdminMenu> menuList = menuService.selectMenuListForRole(map);
        mov.addObject("menuList", menuList);
        return mov;

    }

    @RequestMapping(value = "/welcome")
    public ModelAndView welcome(HttpServletRequest request) {
        System.out.println("=============================index==============================================>>>>>>");
        ModelAndView mov = new ModelAndView();
        mov.setViewName("admin/welcome");
/*Map<String,String> map=new HashMap<>();
        AdminUser adminUser=(AdminUser) request.getSession().getAttribute("user");
        logger.info("adminUser===>>"+adminUser.toString());
map.put("roleId",String.valueOf(adminUser.getRoleId()));
map.put("tid",String.valueOf(adminUser.getTid()));
        List<Map<String,Object>>  menuList= menuService.selectMenuListForRole(map);
mov.addObject("menuList",menuList);*/
        return mov;

    }

}
